﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PSWebLogic;
using System.Web.UI.MobileControls;
using IPSWeb.Logic;


namespace IPSWeb
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tbCommand.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSend.UniqueID + "').click();return false;}} else {return true}; ");
        }

        protected void btnSend_Click(object sender, EventArgs e)
        { 
            if (Session["psrunspace"] == null)
            {

                Session["psrunspace"] = PSUtil.GetNewRunspaceObject(PSConfigurationManager.GetPSSnapInsToAdd(),PSConfigurationManager.GetPSSnapInsToRemove());
            }
            tbShell.Text += string.Format("\n PowerShell Over WEB ==> {0} \n", tbCommand.Text);
            tbShell.Text += PSUtil.ExecuteComand(new List<PSCommand>() { new PSCommand() { CommandText = tbCommand.Text } }, Session["psrunspace"]);
            
        }
    }
}
